package zhzz;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import bingliandshuju.SingleDataofAll;

import com.example.animaldoctor03.AllIllness;
import com.example.animaldoctor03.R;

import commonClass.ADAQueryDiseaseByAnimalIDAction;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import Modle.disease.Symptoms;
import Modle.disease.SymptomsCategorie;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class IllnessDetailofRqst extends Activity {

	private ListView listofIDofRqst ;
	private Button btofRqstttozd , btofRqsttoxq;
	private static int judgefordata = 0;
	
	private String animalIDofIDofRqst = "";
	private static ArrayList<Object> resultListofRqst= null;
	private static  ArrayList<Integer> listofjs = new ArrayList<Integer>();
	private static ArrayList<Object> listofsendinformation = new ArrayList<Object>();
 	
private void chushihuaofIDofRqst(){
	setContentView(R.layout.illnessdetailrqst);
	listofIDofRqst = (ListView)findViewById(R.id.listofIDRqst);
	btofRqstttozd = (Button)findViewById(R.id.btofIDRqst1);
	btofRqsttoxq = (Button)findViewById(R.id.btofIDRqst3);
	

	
}
private void getshujuofIDofRqst(){
	
	Intent intentofIDofRqst = getIntent();
	Bundle dataofIDofRqst =  intentofIDofRqst.getExtras();
	SymptomsCategorie  dataduixiang = (SymptomsCategorie)dataofIDofRqst.getSerializable("shuju");
	animalIDofIDofRqst = dataduixiang.getSymptomsCategorieID();

}
private ArrayList<Object> assemblyofIDofRqst() {

	getshujuofIDofRqst();
	ArrayList<Object> list = new ArrayList<Object>();
	list.add(animalIDofIDofRqst);
	// Integer i = new Integer(10);
	// list.add(i);

	return list;
}

private void bindingofRqst(final ArrayList<Object> list){

	try{
	
		 String[] resultofRqst = new String[list.size()];
		// list.toArray(new String[list.size()]);
		for (int i = 0; i < list.size(); i++) {
			
			
			System.out.println("-------------------------" + ((Symptoms) list.get(i)).getSymptomsCategorieName() );
	
			resultofRqst[i] =((Symptoms) list.get(i)).getSymptomsName() ;
		}
		
		
		
		ArrayAdapter<String> arrayAdapterofResultofillness = new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_multiple_choice, resultofRqst);
		
		listofIDofRqst.setAdapter(arrayAdapterofResultofillness);
		
		listofIDofRqst.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view, int position,
						long id) {
					// TODO Auto-generated method stub
					if(listofjs.size()==0){
						listofjs.add(position);
					}
					else{
						int js = listofjs.size() , jishu = 0;
						for(int i = 0; i < listofjs.size();i++){
							if(position !=(int)listofjs.get(i)){
								jishu++;
								if(jishu == js){
									listofjs.add(position);
								}
							}
						}
					}
				}	 
		 });
		}catch(NullPointerException e){
			android.app.AlertDialog.Builder builderofIND = new AlertDialog.Builder(IllnessDetailofRqst.this);
			builderofIND.setMessage("无数据,请用其他功能");
			builderofIND.create().show();
		}
		
	}	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		chushihuaofIDofRqst();
		ArrayList<Object> parasListofILLD = assemblyofIDofRqst();
		final ArrayList<Object> resultListTofILLD = null;
		
		ADAQueryDiseaseByAnimalIDAction iActionofILLD = new ADAQueryDiseaseByAnimalIDAction();
		
		FunctionDispatcher functionDispacherofBGZZ = new FunctionDispatcher();
		functionDispacherofBGZZ.exceute(RemoteActionsName.QueryAllSymptomsBySymptomsCategorieID, parasListofILLD, iActionofILLD, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				Log.v("ZhengZhuangFZ2", "post:" + resultList.toString());
				IllnessDetailofRqst.this.resultListofRqst = resultList;
				bindingofRqst(resultListofRqst);
			}
		}, this);
		
		btofRqstttozd.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				
				if(judgefordata == 0){
					judgefordata = 1;
					
					SingleDataofAll singleDataofRqst = SingleDataofAll.getInstance();
					List<String> listofindetailofrqsr = new ArrayList<String>();
					List<String> listofindetailofrqsr2 = new ArrayList<String>();
					for(int ids = 0 ; ids <listofjs.size(); ids++){
						/*singleDataofRqst.setObject( (Symptoms)resultListofRqst.get((int)listofjs.get(ids)));*/
						listofsendinformation.add((Symptoms)resultListofRqst.get((int)listofjs.get(ids)));

					}
					singleDataofRqst.setListinformation(listofsendinformation);
					for(int i = 0 ; i < listofsendinformation.size() ; i ++){
						
						listofindetailofrqsr.add(((Symptoms)listofsendinformation.get(i)).getSymptomsName());
						
					}
					singleDataofRqst.setstringinformatin(listofindetailofrqsr);
					for(int i = 0 ; i < listofsendinformation.size() ; i ++){
						
						listofindetailofrqsr2.add(((Symptoms)listofsendinformation.get(i)).getSymptomsID());
						
					}
					singleDataofRqst.setidinformation(listofindetailofrqsr2);
					
					Bundle bundleofRqst= new Bundle ();
					bundleofRqst.putSerializable("shuju",listofsendinformation);
					Intent intentofRqstofzd1 = new Intent(IllnessDetailofRqst.this,AllIllnessOfZH.class);
					intentofRqstofzd1.putExtras(bundleofRqst);
					startActivity(intentofRqstofzd1);
					finish();
				}
				else{

					for(int ids = 0 ; ids <listofjs.size(); ids++){
						
						Bundle bundleofRqst2= new Bundle ();
						bundleofRqst2.putSerializable("shuju", listofsendinformation);
						Intent intentofRqstofzd2 = new Intent(IllnessDetailofRqst.this,AllIllnessOfZH.class);
						intentofRqstofzd2.putExtras(bundleofRqst2);
						startActivity(intentofRqstofzd2);
						finish();
					}
				}
				
			}
		});
		btofRqsttoxq.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(judgefordata == 0){
					judgefordata = 1 ;
					List<String> listofdetailofrqst2 = new ArrayList<String>();
					List<String> listofdetailofrqst = new ArrayList<String>();
					SingleDataofAll singleDataofRqst2 = SingleDataofAll.getInstance();
					for(int ids = 0 ; ids <listofjs.size(); ids++){
						/*singleDataofRqst2.setObject( (Symptoms)resultListofRqst.get((int)listofjs.get(ids)));*/
						listofsendinformation.add((Symptoms)resultListofRqst.get((int)listofjs.get(ids)));
						
					}
					singleDataofRqst2.setListinformation(listofsendinformation);
					
					for(int i = 0 ; i < listofsendinformation.size() ; i++){
						
						listofdetailofrqst.add(((Symptoms)listofsendinformation.get(i)).getSymptomsName());
					}
					singleDataofRqst2.setstringinformatin(listofdetailofrqst);
					for(int i = 0 ; i < listofsendinformation.size() ; i++){
						
						listofdetailofrqst2.add(((Symptoms)listofsendinformation.get(i)).getSymptomsID());
					}
					singleDataofRqst2.setidinformation(listofdetailofrqst2);
					
					Bundle bundleofRqst3= new Bundle ();
					bundleofRqst3.putSerializable("shuju",listofsendinformation);
					Intent intentofRqst3 = new Intent(IllnessDetailofRqst.this,ChoiceDetail.class);
					intentofRqst3.putExtras(bundleofRqst3);
					startActivity(intentofRqst3);
					finish();
				}else{
					for(int ids = 0 ; ids <listofjs.size(); ids++){
						
						
						Bundle bundleofRqst4= new Bundle ();
						bundleofRqst4.putSerializable("shuju", listofsendinformation);
						Intent intentofRqst4 = new Intent(IllnessDetailofRqst.this,ChoiceDetail.class);
						intentofRqst4.putExtras(bundleofRqst4);
						startActivity(intentofRqst4);
						finish();
					}
					
				}
				
			}
		});
	}
	

}
